package com.sun.core.util;

import javax.servlet.http.HttpServletRequest;

public class PagingUtil {
	private HttpServletRequest request;
	public PagingUtil(HttpServletRequest request){
		this.request=request;
	}
	
	public int[] getLimitCause(String frontCurrentPageName,int pageSize,int maxSize){
		int[] a = {1,pageSize,1};
		int currentPage=1;
		int pageCount = 0;
		if(request.getAttribute(frontCurrentPageName)!=null){
			currentPage = Integer.valueOf((String)request.getAttribute(frontCurrentPageName));
		}
		if ((maxSize % pageSize) == 0) {
			pageCount = maxSize / pageSize;
		} else {
			pageCount = maxSize / pageSize + 1;
		}
		if (pageCount == 0) {
			pageCount = 1;
		}

		// 判断pageNum是否过界
		if (currentPage > pageCount && maxSize != 0) {
			currentPage = pageCount;
		}

		// 计算起止记录
		a[0]=(currentPage - 1) * pageSize;
		a[1]=pageSize;
		a[2]=pageCount;
		return a;
	}
}
